<%@ page contentType="text/html;charset=UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>微电影管理系统</title>
    <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
    <link rel="shortcut icon" href="${pageContext.request.contextPath}/resource/static/base/images/logo.png">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/resource/static/admin/bootstrap/css/bootstrap.min.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/resource/static/fonts/css/font-awesome.min.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/resource/static/ionicons/css/ionicons.min.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/resource/static/admin/dist/css/AdminLTE.min.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/resource/static/admin/dist/css/skins/_all-skins.min.css">
    <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/resource/static/admin/plugins/datepicker/datepicker3.css">
    <style>
        *{
            font-family:"Microsoft YaHei";
        }
        .table>tbody>tr>td, .table>tbody>tr>th, .table>tfoot>tr>td, .table>tfoot>tr>th, .table>thead>tr>td, .table>thead>tr>th{
            vertical-align:middle;
            text-align:center;
        }

    </style>
</head>
<body class="hold-transition skin-blue sidebar-mini">
<div class="wrapper">
    <%@ include file="../5-public/AdminSidebar.jsp" %>

    <div class="content-wrapper">
        <!--内容-->
        <section class="content-header">
            <h1>微电影管理系统</h1>
            <input type="text" value="${sessionScope.adminStatus}" hidden="hidden" id="input_status">
            <ol class="breadcrumb">
                <li><a href="#"><i class="fa fa-dashboard"></i> 管理员管理</a></li>
                <li class="active">管理员列表</li>
            </ol>
        </section>
        <section class="content" id="showcontent">
            <div class="row">
                <div class="col-md-12">
                    <div class="box box-primary">
                        <div class="box-header">
                            <h3 class="box-title">管理员列表</h3>
                            <div class="box-tools">
                                <div class="input-group input-group-sm" style="width: 150px;">
                                    <input type="text" name="table_search" class="form-control pull-right"
                                           id="conditionAdmin" placeholder="请输入关键字...">

                                    <div class="input-group-btn" onclick="getByName()">
                                        <button type="submit" class="btn btn-default"><i class="fa fa-search"></i>
                                        </button>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="box-body table-responsive no-padding">
                            <table class="table table-hover">
                                <thead>
                                <tr>
                                    <th>编号</th>
                                    <th>管理员名称</th>
                                    <th>添加时间</th>
                                    <th>管理员头像</th>
                                    <th>管理员类型</th>
                                    <th>操作</th>
                                </tr>
                                </thead>
                                <tbody id="adminlist-tbody">
                                <c:forEach items="${adminlist.list}" var="admin">
                                    <tr>
                                        <td>${admin.personId}</td>
                                        <td>${admin.personName}</td>
                                        <td>${admin.personCreateTime}</td>
                                        <c:choose>
                                            <c:when test="${admin.personImage==null}"><td>暂无头像</td></c:when>
                                            <c:otherwise><td><img width="30" height="30" src="${pageContext.request.contextPath}/resource/static/base/person/${admin.personImage}" class="img-circle"></td></c:otherwise>
                                        </c:choose>
                                        <c:choose>
                                            <c:when test="${admin.personStatus==0}"><td>普通管理员</td></c:when>
                                            <c:when test="${admin.personStatus==1}"><td>超级管理员</td></c:when>
                                            <c:otherwise><td>暂不启用</td></c:otherwise>
                                        </c:choose>
                                        <td>
                                            <a class="label label-success" href="/person/toUserView/${admin.personId}">查看</a>
                                            <c:if test="${sessionScope.adminStatus==1}">
                                                <c:if test="${admin.personStatus==2}">
                                                    <a class="label label-info" onclick="getIce('${admin.personId}',0)">恢复</a>
                                                </c:if>
                                            </c:if>
                                            <c:if test="${sessionScope.adminStatus==1}">
                                                <c:if test="${admin.personName!=sessionScope.adminName and admin.personStatus==0}">
                                                    <a class="label label-danger" onclick="getIce('${admin.personId}',2)">注销</a>
                                                </c:if>
                                            </c:if>
                                        </td>
                                    </tr>
                                </c:forEach>
                                </tbody>
                            </table>
                        </div>
                        <div id="adminlist-page" class="box-footer clearfix">
                            <ul class="pagination pagination-sm no-margin pull-right">
                                <li><a href="#" onclick="getAdminlist(1)">首页</a></li>
                                <c:choose>
                                    <c:when test="${adminlist.isFirstPage}">
                                        <li><a href="#" onclick="getAdminlist(1)">上一页</a></li>
                                    </c:when>
                                    <c:otherwise>
                                        <li><a href="#" onclick="getAdminlist(${adminlist.pageNum-1})">上一页</a></li>
                                    </c:otherwise>
                                </c:choose>
                                <li><a href="#">${adminlist.pageNum}</a></li>
                                <c:choose>
                                    <c:when test="${adminlist.pageNum>=adminlist.pages}">
                                        <li><a href="#" onclick="getAdminlist(${adminlist.pages})">下一页</a></li>
                                    </c:when>
                                    <c:otherwise>
                                        <li><a href="#" onclick="getAdminlist(${adminlist.pageNum + 1})">下一页</a></li>
                                    </c:otherwise>
                                </c:choose>
                                <li><a href="#" onclick="getAdminlist(${adminlist.pages})">尾页</a></li>
                            </ul>
                        </div>
                    </div>
                </div>
            </div>
        </section>
        <!--内容-->
    </div>
    <footer class="main-footer">
        <div class="pull-right hidden-xs">
            <b>版本</b> 1.0
        </div>
        <strong>版权 &copy; 2017-2018 归<a href="">xxx</a>.</strong> 所有
    </footer>
    <div class="control-sidebar-bg"></div>
</div>
<script src="${pageContext.request.contextPath}/resource/static/admin/plugins/jQuery/jQuery-2.2.0.min.js"></script>
<script src="${pageContext.request.contextPath}/resource/static/admin/bootstrap/js/bootstrap.min.js"></script>
<script src="${pageContext.request.contextPath}/resource/static/admin/plugins/slimScroll/jquery.slimscroll.min.js"></script>
<script src="${pageContext.request.contextPath}/resource/static/admin/plugins/fastclick/fastclick.js"></script>
<script src="${pageContext.request.contextPath}/resource/static/admin/dist/js/app.min.js"></script>
<script src="${pageContext.request.contextPath}/resource/static/admin/dist/js/demo.js"></script>
<script src="//cdn.bootcss.com/holder/2.9.4/holder.min.js"></script>
<script src="${pageContext.request.contextPath}/resource/static/admin/plugins/datepicker/bootstrap-datepicker.js"></script>
<script src="${pageContext.request.contextPath}/resource/static/admin/plugins/datepicker/locales/bootstrap-datepicker.zh-CN.js" charset="UTF-8"></script>
<script>
    function getIce(index, statues) {
        var data = {
            "personId": index,
            "status": statues
        }
        $.ajax({
            url: "/person/updateStatus",
            data: data,
            type: "post",
            dataType: "json",
            success: function (res) {
                alert(res.msg);
                if(res.code=="200"){
                    window.location.reload();
                }
            },
            error: function (e1, e2, e3) {
                console.log(e1)
                console.log(e2)
                console.log(e3)
            }
        })

    }

    var adminstatus=$("#input_status").val();
    function getAdminlist(index) {
        var data = {
            "pageNum": index,
            "pageSize": 10,
            "role": 1
        }
        $.ajax({
            url: "/person/personPage",
            data: data,
            type: "get",
            dataType: "json",
            success: function (res) {
                var body = $("#adminlist-tbody");
                body.empty();
                for (let i = 0; i < res.data.list.length; i++) {
                    var date = new Date(res.data.list[i].personCreateTime).toLocaleDateString();
                    var time = new Date(res.data.list[i].personCreateTime).toLocaleTimeString();
                    var tr='<tr>'+
                        '<td>'+res.data.list[i].personId+'</td>'+
                        '<td>'+res.data.list[i].personName+'</td>'+
                        '<td>'+date+''+time+ '</td>';
                    if(res.data.list[i].personImage==null){
                        tr=tr+'<td>暂无头像</td>';
                    }else {
                        tr = tr + '<td><img width="30" height="30" src="/resource/static/base/person/'+res.data.list[i].personImage+'" class="img-circle"></td>';
                    }
                    if(res.data.list[i].personStatus==0){
                        tr=tr+'<td>普通管理员</td>';
                    }else if(res.data.list[i].personStatus==1){
                        tr=tr+'<td>超级管理员</td>';
                    }else {
                        tr=tr+'<td>暂不启用</td>';
                    }
                    tr=tr+'<td><a class="label label-success" href="/person/toUserView/'+res.data.list[i].personId+'">查看</a>';
                    if (adminstatus==1){
                        if (res.data.list[i].personStatus==2){
                            tr=tr+'<a class="label label-info" onclick="getIce('+res.data.list[i].personId.toString()+',0)">恢复</a>';
                        }else {
                            tr=tr+' <a class="label label-danger" onclick="getIce('+res.data.list[i].personId.toString()+',2)">注销</a>';
                        }
                    }
                    tr=tr+'</td>'
                    body.append(tr);
                }
                var page = $("#adminlist-page");
                page.empty();
                var li = '<ul class="pagination pagination-sm no-margin pull-right">' +
                    '<li><a href="#" onclick="getAdminlist(1)">首页</a></li>';
                if (res.data.pageNum > 1) {
                    li = li + '<li><a href="#" onclick="getAdminlist(' + (res.data.pageNum - 1) + ')">上一页</a></li>';
                } else {
                    li = li + '<li><a href="#" onclick="getAdminlist(' + res.data.pageNum + ')">上一页</a></li>';
                }
                li = li + '<li><a href="#">' + res.data.pageNum + '</a></li>'
                if (res.data.pageNum >= res.data.pages) {
                    li = li + '<li><a href="#" onclick="getAdminlist(' + (res.data.pages) + ')">下一页</a></li>'
                } else {
                    li = li + '<li><a href="#" onclick="getAdminlist(' + (res.data.pageNum + 1) + ')">下一页</a></li>'
                }

                li = li + '<li><a href="#" onclick="getAdminlist(' + res.data.pages + ')">尾页</a></li>' + '</ul>';
                page.append(li);
            },
            error: function () {
                alert("小二正忙，一会再试");
            }
        })
    }

    function getByName() {
        var name=$("#conditionAdmin").val();
        var data={
            "selectName":name,
            "personRole":1
        }
        $.ajax({
            url: "/person/selectLikeName",
            data: data,
            type: "post",
            dataType: "json",
            success: function (res) {
                if (res.code=="400"){
                    alert(res.msg);
                }
                else {
                    var body = $("#adminlist-tbody");
                    body.empty();
                    for (let i = 0; i < res.data.list.length; i++) {
                        var date = new Date(res.data.list[i].personCreateTime).toLocaleDateString();
                        var time = new Date(res.data.list[i].personCreateTime).toLocaleTimeString();
                        var tr='<tr>'+
                            '<td>'+res.data.list[i].personId+'</td>'+
                            '<td>'+res.data.list[i].personName+'</td>'+
                            '<td>'+date+''+time+ '</td>';
                        if(res.data.list[i].personImage==null){
                            tr=tr+'<td>暂无头像</td>';
                        }else {
                            tr = tr + '<td><img width="30" height="30" src="/resource/static/base/person/'+res.data.list[i].personImage+'" class="img-circle" ></td>';
                        }
                        if(res.data.list[i].personStatus==0){
                            tr=tr+'<td>普通管理员</td>';
                        }else if(res.data.list[i].personStatus==1){
                            tr=tr+'<td>超级管理员</td>';
                        }else {
                            tr=tr+'<td>暂不启用</td>';
                        }
                        tr=tr+'<td><a class="label label-success" href="/person/toUserView/'+res.data.list[i].personId+'">查看</a>';
                        if (adminstatus==1){
                            if (res.data.list[i].personStatus==2){
                                tr=tr+'<a class="label label-info" onclick="getIce('+res.data.list[i].personId.toString()+',0)">恢复</a>';
                            }else {
                                tr=tr+' <a class="label label-danger" onclick="getIce('+res.data.list[i].personId.toString()+',2)">注销</a>';
                            }
                        }
                        tr=tr+'</td>'
                        body.append(tr);
                    }
                    var page = $("#adminlist-page");
                    page.empty();
                    var li = '<ul class="pagination pagination-sm no-margin pull-right">' +
                        '<li><a href="#" onclick="getSelectlist(1)">首页</a></li>';
                    if (res.data.pageNum > 1) {
                        li = li + '<li><a href="#" onclick="getSelectlist(' + (res.data.pageNum - 1) + ')">上一页</a></li>';
                    } else {
                        li = li + '<li><a href="#" onclick="getSelectlist(' + res.data.pageNum + ')">上一页</a></li>';
                    }
                    li = li + '<li><a href="#">' + res.data.pageNum + '</a></li>'
                    if (res.data.pageNum >= res.data.pages) {
                        li = li + '<li><a href="#" onclick="getSelectlist(' + (res.data.pages) + ')">下一页</a></li>'
                    } else {
                        li = li + '<li><a href="#" onclick="getSelectlist(' + (res.data.pageNum + 1) + ')">下一页</a></li>'
                    }

                    li = li + '<li><a href="#" onclick="getSelectlist(' + res.data.pages + ')">尾页</a></li>' + '</ul>';
                    page.append(li);
                }
            },
            error: function (e1, e2, e3) {
                console.log(e1)
                console.log(e2)
                console.log(e3)
            }
        })
    }

    function getSelectlist(index) {
        var name=$("#conditionAdmin").val();
        var data = {
            "pageNum": index,
            "pageSize": 10,
            "selectName":name,
            "personRole":1
        }
        $.ajax({
            url: "/person/personSelectPage",
            data: data,
            type: "get",
            dataType: "json",
            success: function (res) {
                var body = $("#adminlist-tbody");
                body.empty();
                for (let i = 0; i < res.data.list.length; i++) {
                    var date = new Date(res.data.list[i].personCreateTime).toLocaleDateString();
                    var time = new Date(res.data.list[i].personCreateTime).toLocaleTimeString();
                    var tr='<tr>'+
                        '<td>'+res.data.list[i].personId+'</td>'+
                        '<td>'+res.data.list[i].personName+'</td>'+
                        '<td>'+date+''+time+ '</td>';
                    if(res.data.list[i].personImage==null){
                        tr=tr+'<td>暂无头像</td>';
                    }else {
                        tr = tr + '<td><img width="30" height="30" src="/resource/static/base/person/'+res.data.list[i].personImage+'" class="img-circle" ></td>';
                    }
                    if(res.data.list[i].personStatus==0){
                        tr=tr+'<td>普通管理员</td>';
                    }else if(res.data.list[i].personStatus==1){
                        tr=tr+'<td>超级管理员</td>';
                    }else {
                        tr=tr+'<td>暂不启用</td>';
                    }
                    tr=tr+'<td><a class="label label-success" href="/person/toUserView/'+res.data.list[i].personId+'">查看</a>';
                    if (adminstatus==1){
                        if (res.data.list[i].personStatus==2){
                            tr=tr+'<a class="label label-info" onclick="getIce('+res.data.list[i].personId.toString()+',0)">恢复</a>';
                        }else {
                            tr=tr+' <a class="label label-danger" onclick="getIce('+res.data.list[i].personId.toString()+',2)">注销</a>';
                        }
                    }
                    tr=tr+'</td>'
                    body.append(tr);
                }
                var page = $("#adminlist-page");
                page.empty();
                var li = '<ul class="pagination pagination-sm no-margin pull-right">' +
                    '<li><a href="#" onclick="getSelectlist(1)">首页</a></li>';
                if (res.data.pageNum > 1) {
                    li = li + '<li><a href="#" onclick="getSelectlist(' + (res.data.pageNum - 1) + ')">上一页</a></li>';
                } else {
                    li = li + '<li><a href="#" onclick="getSelectlist(' + res.data.pageNum + ')">上一页</a></li>';
                }
                li = li + '<li><a href="#">' + res.data.pageNum + '</a></li>'
                if (res.data.pageNum >= res.data.pages) {
                    li = li + '<li><a href="#" onclick="getSelectlist(' + (res.data.pages) + ')">下一页</a></li>'
                } else {
                    li = li + '<li><a href="#" onclick="getSelectlist(' + (res.data.pageNum + 1) + ')">下一页</a></li>'
                }

                li = li + '<li><a href="#" onclick="getSelectlist(' + res.data.pages + ')">尾页</a></li>' + '</ul>';
                page.append(li);
            },
            error: function () {
                alert("小二正忙，一会再试");
            }
        })
    }
</script>

</body>
</html>